﻿using Customer.API.Applcation.Command.ClientCommand;
using Customer.Infrstructre.ClientManager;
using MediatR;

namespace Customer.API.Applcation.CommandHandlers.ClientCommandHandler
{
    /// <summary>
    /// 删除客户
    /// </summary>
    public class ClientDelCommandHandler:IRequestHandler<ClientDelCommand,int>
    {
        private readonly IClientRepository _clientRep;
        public ClientDelCommandHandler(IClientRepository _clientRep)
        {
            this._clientRep = _clientRep;
        }

        public async Task<int> Handle(ClientDelCommand request, CancellationToken cancellationToken)
        {
            //批删
            foreach (var item in request.ClientId)
            {
                var list = await _clientRep.GetModelAsync(item);
                list.IsDel = true;
                await _clientRep.Update(list);
            }
            return 1;
        }
    }
}
